package com.boe.csb.web.controller.csb;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csb.console.sdk.Result;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.boe.csb.core.common.exception.CSBErrorCode;
import com.boe.csb.core.dao.BoeApiInfoMapper;
import com.boe.csb.core.dao.BoeUserMapper;
import com.boe.csb.core.entity.ResultInfo;
import com.boe.csb.core.entity.UserInfo;
import com.boe.csb.core.service.csb.CsbAuditApiService;
import com.boe.csb.core.service.user.BoeUserService;
import com.boe.csb.web.controller.BaseController;
import com.boe.csb.web.controller.base.BoeUserController;
import com.boe.csb.web.model.ResultModel;

/**
 * Created by tianxiang.luo on 16/12/4.
 *
 * 1.管理员审核发布服务
 *
 */

@RestController
@RequestMapping("/api/audit/service")
public class CsbAuditServiceController extends BaseController{


    @Autowired
    private CsbAuditApiService csbAuditApiService;
    @Autowired
    private BoeUserService boeUserService;
    @Autowired
    private BoeApiInfoMapper boeApiInfoMapper;
    @Autowired
    private BoeUserMapper boeUserMapper;


    /**
     * 审核发布服务, 获取所有人发布的列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResultModel findServices(HttpSession session, @RequestParam Integer pageNum,
                                    @RequestParam(required = false) String serviceName,
                                    @RequestParam(required = false) String alias,
                                    @RequestParam(required = false) String showDelService,
                                    @RequestParam(required = false)String showPendingServiceOnly) throws UnsupportedEncodingException {
        String userId = fetchUserId(session);
        
        Result result = csbAuditApiService.adminFindService(userId, pageNum, serviceName,alias,showDelService,showPendingServiceOnly);
        return ResultModel.success(result.getData());
    }


    /**
     * 审核发布服务
     */
    @RequestMapping(value = "/audit", method = RequestMethod.POST)
    public ResultModel<JSONObject> updateServicesStatus(HttpSession session,@RequestParam Long id, @RequestParam String comment, @RequestParam boolean status) {
        String userId = fetchUserId(session);
        return ResultModel.success(csbAuditApiService.approveService(userId,id,comment,status).getData());
    }






}
